package great.easychat.help.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.lifecycle.Observer;

import java.util.Locale;

import great.easychat.help.BaseActivity;
import great.easychat.help.CustomAppcation;
import great.easychat.help.R;
import great.easychat.help.bean.SuggestBean;
import great.easychat.help.util.DebugLog;
import great.easychat.help.util.ToastUtil;
import great.easychat.help.util.Util;
import great.easychat.help.viewModel.CommonViewModel;

public class SuggestActivity extends BaseActivity<CommonViewModel> implements View.OnClickListener {

    EditText etSuggest;
    Button btnSubmit;

    @Override
    protected void observeLiveData() {
        viewModel.getSuggestLiveData().observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                btnSubmit.setEnabled(true);
                if (aBoolean) {
                    ToastUtil.show("提交成功");
                    finish();
                } else {
                    ToastUtil.show("提交失败，请联系客服");
                }
            }
        });
    }

    @Override
    public int requestLayoutId() {
        return R.layout.activity_suggest;
    }

    @Override
    public void setViewData(Bundle savedInstanceState) {
        etSuggest = findViewById(R.id.etSuggest);
        btnSubmit = findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(this);
        setTitle("投诉建议");
    }


    @Override
    public void onClick(View view) {
        if (view == btnSubmit) {
            String msg = etSuggest.getText().toString();
            if (!msg.isEmpty()) {
                btnSubmit.setEnabled(false);
                viewModel.submitSuggest(new SuggestBean(msg, getString(R.string.app_name), Util.getAppVersionName(CustomAppcation.context), android.os.Build.BRAND + "_" + android.os.Build.MODEL + " " + android.os.Build.VERSION.RELEASE + " - " + Locale.getDefault().getLanguage() ));
            } else {
                ToastUtil.show("请输入您的建议");
            }
        }
    }

    @Override
    protected boolean isToolBarEnable() {
        return false;
    }
}
